public class Hotel {
    Room[][] rooms;//假设酒店有三层，每层有5个房间

    public Hotel() {
        rooms = new Room[3][5];//给每个房间申请一个空间
        for (int i = 0; i < rooms.length; i++) {//赋值
            for (int j = 0; j < rooms[i].length; j++) {
                if (i == 0) {
                    rooms[i][j] = new Room(100 * (i + 1) + j + 1, "单人房", true);
                } else if (i == 1) {
                    rooms[i][j] = new Room(100 * (i + 1) + j + 1, "标准间", true);
                } else {
                    rooms[i][j] = new Room(100 * (i + 1) + j + 1, "大床房", true);
                }

            }
        }
    }

    public void printState() {
        for (int i = 0; i < rooms.length; i++) {
            for (int j = 0; j < rooms[i].length; j++) {
                System.out.print(rooms[i][j] + " ");
            }
            System.out.println();
        }
    }

    public static void main(String[] args) {
        Hotel hotel = new Hotel();
        hotel.printState();
        hotel.order(204);
        hotel.printState();
        hotel.refund(204);
        hotel.printState();


    }

    //订房 输入编号 设置房间state =false
    public void order(int num) {
        if (!rooms[num / 100 - 1][num % 100 - 1].getState()) {
            System.out.println("房间已被占用");
        } else {
            rooms[num / 100 - 1][num % 100 - 1].setState(false);
            System.out.println(num + "已定房");
        }

    }

    //退房
    public void refund(int num) {
        if (rooms[num / 100 - 1][num % 100 - 1].getState()) {
            System.out.println("房间本来就是空的！");
        } else {
            rooms[num / 100 - 1][num % 100 - 1].setState(true);
            System.out.println(num + "已退房");
        }
    }
}





